package com.test.ita;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 * User: gpss
 * Date: 7/4/11
 * Time: 10:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class PatternMatcher {

    public static MatchResult match(String patternStr, String word) {
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(word);

        MatchResult mr = new MatchResult(false);

        while (matcher.find()) {
            mr.setFound(true);
            mr.setStart(matcher.start());
            mr.setEnd(matcher.end());
        }

        return mr;

    }

    public static void main (String[] args) {
        MatchResult result = PatternMatcher.match("d[a-z]*e","first,hhhdovee");

        System.out.println("Result : "+result.isFound());
        System.out.println("Start : "+result.getStart());
        System.out.println("end : "+result.getEnd());

    }
}
